<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        span {
            width: 100px;
            height: 50px;
            line-height: 50px;
            color: cornflowerblue;
            background-color: darkgreen;
        }
    </style>
</head>

<body>
    <button>点击显示系统的时间</button> <span>当前系统的时间为：xxxx</span>
    <script>
        // 第一步获取button按钮对象，然后给button添加单击事件
        const btnObj = document.querySelector("button");
        const spanObj = document.querySelector("span");

        btnObj.onclick = function () {
            spanObj.innerText = getTime();
        }

        function getTime() {
            const time = new Date();
            return time;
        }
    </script>
</body>

</html>